package com.changcheng.project.ble_userinfo.controller;

import java.util.ArrayList;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.changcheng.framework.aspectj.lang.annotation.Log;
import com.changcheng.framework.aspectj.lang.enums.BusinessType;
import com.changcheng.project.ble_userinfo.domain.ABleUserinfo;
import com.changcheng.project.ble_userinfo.service.IABleUserinfoService;
import com.changcheng.framework.web.controller.BaseController;
import com.changcheng.framework.web.domain.AjaxResult;
import com.changcheng.common.utils.poi.ExcelUtil;
import com.changcheng.framework.web.page.TableDataInfo;

/**
 * BLE用户列表Controller
 * 
 * @author dazhi
 * @date 2021-03-10
 */
@Controller
@RequestMapping("/ble_userinfo/ble_userinfo")
public class ABleUserinfoController extends BaseController
{
    private String prefix = "ble_userinfo/ble_userinfo";

    @Autowired
    private IABleUserinfoService aBleUserinfoService;

    @RequiresPermissions("ble_userinfo:ble_userinfo:view")
    @GetMapping()
    public String ble_userinfo()
    {
        return prefix + "/ble_userinfo";
    }

    /**
     * 查询BLE用户列表列表
     */
    @RequiresPermissions("ble_userinfo:ble_userinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ABleUserinfo aBleUserinfo)
    {
        startPage();
        List<ABleUserinfo> list = aBleUserinfoService.selectABleUserinfoList(aBleUserinfo);
        return getDataTable(list);
    }
    /**
     * 查询BLE用户列表列表
     */

    @PostMapping("/listforfactory")
    @ResponseBody
    public TableDataInfo listforfactory(ABleUserinfo aBleUserinfo)
    {
        List<String> list=new ArrayList<>();
        startPage();
        List<ABleUserinfo> list2 = aBleUserinfoService.selectABleUserinfoList(aBleUserinfo);
        for (int i = 0; i < list2.size(); i++) {
            list.add(list2.get(i).getCompany());
        }
        return getDataTable(list);
    }
    /**
     * 导出BLE用户列表列表
     */
    @RequiresPermissions("ble_userinfo:ble_userinfo:export")
    @Log(title = "BLE用户列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ABleUserinfo aBleUserinfo)
    {
        List<ABleUserinfo> list = aBleUserinfoService.selectABleUserinfoList(aBleUserinfo);
        ExcelUtil<ABleUserinfo> util = new ExcelUtil<ABleUserinfo>(ABleUserinfo.class);
        return util.exportExcel(list, "ble_userinfo");
    }

    /**
     * 新增BLE用户列表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存BLE用户列表
     */
    @RequiresPermissions("ble_userinfo:ble_userinfo:add")
    @Log(title = "BLE用户列表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ABleUserinfo aBleUserinfo)
    {
        return toAjax(aBleUserinfoService.insertABleUserinfo(aBleUserinfo));
    }

    /**
     * 修改BLE用户列表
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ABleUserinfo aBleUserinfo = aBleUserinfoService.selectABleUserinfoById(id);
        mmap.put("aBleUserinfo", aBleUserinfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存BLE用户列表
     */
    @RequiresPermissions("ble_userinfo:ble_userinfo:edit")
    @Log(title = "BLE用户列表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ABleUserinfo aBleUserinfo)
    {
        return toAjax(aBleUserinfoService.updateABleUserinfo(aBleUserinfo));
    }

    /**
     * 删除BLE用户列表
     */
    @RequiresPermissions("ble_userinfo:ble_userinfo:remove")
    @Log(title = "BLE用户列表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(aBleUserinfoService.deleteABleUserinfoByIds(ids));
    }
}
